package com.lemon.exam.common.properties;

import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.teaopenapi.models.Config;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 * 阿里云 短信 OSS 配置信息
 *
 * @author Lemon
 * @since 2025/4/9 19:37
 */
@Setter
@Getter
@Component
@ConfigurationProperties(prefix = "aliyun")
public class AliyunProperties {
    private Sms sms;
    private Oss oss;

    @Setter
    @Getter
    public static class Sms {
        //阿里云短信服务ID
        private String accessKeyId;
        //阿里云短信服务秘钥
        private String accessKeySecret;
        //阿里云短信端点
        private String endpoint;
        //短信签名
        private String signName;

        public Client client() throws Exception {
            return new Client(new Config()
                    .setAccessKeyId(accessKeyId)
                    .setAccessKeySecret(accessKeySecret)
                    .setEndpoint(endpoint));
        }
    }

    @Setter
    @Getter
    public static class Oss {
        //阿里云OSS端点
        private String endpoint;
        //阿里云OSS访问ID
        private String accessKeyId;
        //阿里云OSS访问密钥
        private String accessKeySecret;

        public OSS oss() {
            return new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
        }
    }
}
